using System;

namespace HelloWorld.Helper
{
    public class Queue
    {
        Entry first;
        Entry last;

        public void Push(object data)
        {
            last = new Entry(last, data);
            if (first == null)
                first = last;
        }

        public object Pop()
        {
            if (first == null)
            {
                throw new InvalidOperationException();
            }

            object result = first.data;
            first = first.next;

            return result;
        }

        class Entry
        {
            public Entry next;
            public object data;

            public Entry(Entry next, object data)
            {
                if (next == null)
                    next = this;

                this.data = data;
                next.next = this;
            }
        }
    }
}
